<template>
  <el-dropdown @command="handleCommand">
    <vab-icon :icon="icon" />
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item command="silent">静默打印</el-dropdown-item>
        <el-dropdown-item command="preview">预览打印</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script>
  import { mapActions, mapGetters } from 'vuex'

  export default {
    name: 'VabPrint',
    computed: {
      ...mapGetters(['printType']),
      icon() {
        return this.printType === 'preview' ? 'printer-line' : 'printer-fill'
      },
    },
    methods: {
      ...mapActions({
        changePrintType: 'settings/changePrintType',
      }),
      handleCommand(command) {
        this.changePrintType(command)
        this.$baseMessage('切换成功', 'success', 'vab-hey-message-success')
      },
    },
  }
</script>
